{extend name="common:base"}
{block name="body"}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="pid" class="layui-form-label">
                    <span class="x-red">*</span>父节点
                </label>
                <div class="layui-input-inline">
                    <select id="pid" name="pid" lay-verify="required">
                        <option value=""></option>
                        <option value="0">顶级分类</option>
                        {volist name="list" id="vo"}
                        {if($vo.id == $result.pid)}
                        <option value="{$vo.id}" selected>{$vo.name}</option>
                        {else /}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/if}
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>权限名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required"
                           value="{$result.name}"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="handler" class="layui-form-label">
                    <span class="x-red">*</span>权限节点
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="handler" name="handler" required="" lay-verify="required"
                           value="{$result.handler}"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <input type="hidden" name="id" value="{$result.id}">
            <div class="layui-form-item">
                <label for="add" class="layui-form-label"></label>
                <button id="add" class="layui-btn" lay-filter="add" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="copyright"}

{/block}
{block name="javascript"}
<script>
    layui.use(['form', 'layer'], function () {
        const $ = layui.jquery;
        const form = layui.form,
            layer = layui.layer;
        //监听提交
        form.on('submit(add)',
            function (data) {
                $.ajax({
                    url:'{:url(\'edit_permission\',[\'id\'=>$result.id])}',
                    type:'POST',
                    data:data.field,
                    success:function (result) {
                        if(result.status === 1){
                            layer.msg(result.message, {icon: 6,time:1000}, function () {
                                xadmin.father_reload();
                            });
                        }else {
                            layer.msg(result.message,{icon:5,time:2000});
                        }
                    }
                },'JSON');
                return false;
            });
    });
</script>
{/block}